package com.atguigu.yygh.hosp.controller;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.hosp.service.HospitalService;
import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author:ahang
 * @create:2022-09-03 18:21
 * @Description:
 */
//@CrossOrigin
@Api(description = "医院接口")
@RestController
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation("带条件的分页查询")
    //注意:get请求不能使用@requestBody,前端对应传参数使用param(请求使用data)
    @GetMapping("{page}/{limit}")
    public R index(@PathVariable Integer page, @PathVariable Integer limit, HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitals = hospitalService.selectPage(page, limit, hospitalQueryVo);

        return R.ok().data("pages",hospitals);
    }

    @ApiOperation("修改状态")
    @GetMapping("updateStatus/{id}/{status}")
    public R updateStatus(@PathVariable("id") String id,@PathVariable("status") Integer status){
        hospitalService.updateStatus(id,status);
        return R.ok();
    }

    @ApiOperation("医院详情接口")
    @GetMapping("show/{id}")
    public R show(@PathVariable("id") String id){
        Map<String, Object> map = hospitalService.show(id);
        //data{hospital:{hospital:{},bookingRule:{} } }
        return R.ok().data("hospital",map);
    }
}
